#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const int N=1e5+3;
const int M=1e6+3;
int cnt[N][2];
int T,n,m,L,V;

int d[N],v[N],a[N];
int p[N];
int ans;

struct node{
	int u,num;
}pre[N];

int read(){
	int x;
	scanf("%d",&x);
	return x;
}

bool cmp(node x,node y){
	return x.num>y.num;
}
bool check(){
	for(int i=1;i<=m;i++){
		if(pre[i].num>0)return true;
	}
	return false;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	T=read();
	while(T--){
		ans=0;
		memset(d,0,sizeof d);
		memset(v,0,sizeof v);
		memset(a,0,sizeof a);
		memset(p,0,sizeof p);
		n=read(),m=read(),L=read(),V=read();
		for(int i=1;i<=n;i++){
			d[i]=read(),v[i]=read(),a[i]=read();
			cnt[i][0]=-1,cnt[i][1]=-1;
			if(a[i]==0){
				if(v[i]>V){
					cnt[i][0]=d[i],cnt[i][1]=L;
				}
			}
			if(a[i]<0){
				a[i]*=-1;
				if(v[i]>V){
					cnt[i][0]=d[i];
					ll chk=(1ll*v[i]*v[i]-2*a[i]*(L-d[i]));
					if(chk>1ll*V*V){
						cnt[i][1]=L;
					}
					else{
						ll xi=(1ll*v[i]*v[i]-V*V);
						ll tmp=(xi)%(2*a[i]);
						xi/=(2*a[i]);
						xi+=d[i];
						cnt[i][1]=xi-(tmp==0);
					}
				}
				a[i]*=-1;
			}
			if(a[i]>0){
				if(v[i]>=V){
					cnt[i][0]=d[i]+(v[i]==V);
					cnt[i][1]=L;
				}
				else{
					ll chk=1ll*v[i]*v[i]+2*1ll*a[i]*(L-d[i]);
					if(chk>(1ll*V*V)){
						ll xi=(1ll*V*V-1ll*v[i]*v[i]);
						xi/=(2*a[i]);
						xi+=d[i];
						if(xi>1ll*L)cnt[i][0]=L;
						else cnt[i][0]=xi+1;
						cnt[i][1]=L;
					}
				}
			}
		}
		for(int i=1;i<=m;i++){
			p[i]=read();
			node t;
			t.u=p[i],t.num=0;
			for(int j=1;j<=n;j++){
				if(cnt[j][0]<0)continue;
				if(cnt[j][0]<=p[i]&&p[i]<=cnt[j][1])t.num++;
			}
			pre[i]=t;
		}
		sort(pre+1,pre+m+1,cmp);
		for(int i=1;i<=n;i++){
			if(cnt[i][0]<0)continue;
			for(int j=1;j<=m;j++){
				if(cnt[i][0]<=p[j]&&p[j]<=cnt[i][1]){
					ans++;
					break;
				}
			}
		}
		printf("%d ",ans);
		sort(pre+1,pre+m+1,cmp);
		ans=m;
		while(check()){
			ans--;
			int ind=pre[1].u;
			pre[1].num=0;
			for(int i=1;i<=n;i++){
				if(cnt[i][0]<=ind&&ind<=cnt[i][1]){
					for(int j=2;j<=m;j++){
						if(cnt[i][0]<=pre[j].u && pre[j].u<=cnt[i][1]){
							pre[j].num--;
						}
					}
				}
			}
			sort(pre+1,pre+m+1,cmp);
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
